package com.dfhz.ken.mypubapplication;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.dfhz.ken.mypubapplication.widget.PullToRefrshLinearLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Author:Ken
 * Data：2018/12/5-10:32
 * Todo: doit
 */

public class PullRefrshActivity extends AppCompatActivity {
    @Bind(R.id.listview)
    ListView listview;
    @Bind(R.id.lin_refresh)
    PullToRefrshLinearLayout linRefresh;
    Handler handler = new Handler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pullrefresh);
        ButterKnife.bind(this);
        init();
        initEvent();
    }

    private void init(){
        String[] strs = {"子鼠","丑牛","寅虎","卯兔","辰龙","巳蛇","午马","未羊","申猴","酉鸡","戌狗亥猪","亥猪","子鼠","丑牛","寅虎","卯兔","辰龙","巳蛇","午马","未羊","申猴","酉鸡","戌狗亥猪","亥猪"};
        //创建ArrayAdapter
        ArrayAdapter<String> adapter = new ArrayAdapter<String>
                (this,android.R.layout.simple_expandable_list_item_1,strs);
        listview.setAdapter(adapter);
    }

    private void initEvent(){
//        linRefresh.hideFooterView();
        linRefresh.setOnHeaderRefreshListener(new PullToRefrshLinearLayout.OnHeaderRefreshListener() {
            @Override
            public void onHeaderRefresh(PullToRefrshLinearLayout view) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        linRefresh.onHeaderRefreshComplete();
//                        linRefresh.showFooterView();
                    }
                },2000);
            }
        });

        linRefresh.setOnFooterRefreshListener(new PullToRefrshLinearLayout.OnFooterRefreshListener() {
            @Override
            public void onFooterRefresh(PullToRefrshLinearLayout view) {
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        linRefresh.onFooterRefreshComplete();
                    }
                },2000);
            }
        });
    }


}
